package homework.Demo_1;

import com.sun.org.apache.bcel.internal.generic.NEW;
import org.omg.CORBA.TRANSACTION_MODE;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Client {
//    private Socket socket;
//    public Client(){
//        try {
//            System.out.println("正在连接服务端---");
//            socket = new Socket("localhost",8088);
//            System.out.println("连接服务端完毕!");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//    public void start(){
//        try {
//            OutputStream os = socket.getOutputStream();
//            OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
//            BufferedWriter bw = new BufferedWriter(osw);
//            PrintWriter pw = new PrintWriter(bw,true);
//            pw.println("haoyayu");
//            System.out.println("链接完毕!");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//    public static void main(String[] args) {
//        Client socket = new Client();
//        socket.start();
//
//    }
//    public Socket socket;
//    private Client(){
//        try {
//            System.out.println("正在连接服务端---");
//            socket = new Socket("localhost",8088);
//            System.out.println("服务端连接成功!");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//    private void stact(){
//        try {
//            OutputStream out = socket.getOutputStream();
//            OutputStreamWriter osw = new OutputStreamWriter(out,"UTF-8");
//            BufferedWriter bw = new BufferedWriter(osw);
//            PrintWriter pw = new PrintWriter(bw,true);
//            pw.println("你好呀!");
//            System.out.println("程序结束!");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//    public static void main(String[] args) {
//        Client socket = new Client();
//        socket.stact();
//
//    }
//    private Socket socket;
//    public Client(){
//        try {
//            System.out.println("正在连接服务端--");
//            socket = new Socket("localhost",8088);
//            System.out.println("服务端连接完毕!");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//    public void Start(){
//        try {
//            OutputStream os = socket.getOutputStream();
//            OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
//            BufferedWriter bw = new BufferedWriter(osw);
//            PrintWriter pw = new PrintWriter(bw,true);
//            pw.println("第四遍!!!");
//            System.out.println("程序结束!");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//    }
//
//    public static void main(String[] args) {
//        Client client = new Client();
//        client.Start();
//    }
//    private Socket socket;
//    public Client(){
//        try {
//            System.out.println("正在连接服务端....");
//            socket = new Socket("localhost",8088);
//            System.out.println("服务端连接完毕!");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//    public void Start(){
//        try {
//            OutputStream os = socket.getOutputStream();
//            OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
//            BufferedWriter bw = new BufferedWriter(osw);
//            PrintWriter pw = new PrintWriter(bw,true);
//            pw.println("第五遍,大功告成!");
//            System.out.println("程序结束!");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//    public static void main(String[] args) {
//        Client client = new Client();
//        client.Start();
//
//    }
//    private Socket socket;
//    public Client(){
//        try {
//            System.out.println("正在启动客户端---");
//            socket = new Socket("localhost",8088);
//            System.out.println("客户端启动完毕!");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//    public void sater(){
//        try {
//            OutputStream os = socket.getOutputStream();
//            OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
//            BufferedWriter bw = new BufferedWriter(osw);
//            PrintWriter pw = new PrintWriter(bw, true);
//            Scanner sc = new Scanner(System.in);
//            System.out.println("可以开始说话了,单独输入exit时退出!");
//            while (true) {
//                String line = sc.nextLine();
//                if ("exit".equalsIgnoreCase(line)){
//                    break;
//                }
//                pw.println(line);
//            }
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//    }
//
//    public static void main(String[] args) {
//        Client client = new Client();
//        client.sater();
//    }
//    private Socket socket;
//    public Client(){
//        try {
//            System.out.println("正在启动客户端-------");
//            socket = new Socket("localhost",8088);
//            System.out.println("客户端已启动!");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//    public void sater(){
//        try {
//            OutputStream os = socket.getOutputStream();
//            OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
//            BufferedWriter bw = new BufferedWriter(osw);
//            PrintWriter pw = new PrintWriter(bw,true);
//            Scanner sc = new Scanner(System.in);
//            System.out.println("可以开始输入了,单独输入exit时退出");
//            while (true) {
//                String line = sc.nextLine();
//                if ("exit".equalsIgnoreCase(line)){
//                    break;
//                }
//                pw.println(line);
//
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//    public static void main(String[] args) {
//        Client client = new Client();
//        client.sater();
//    }
    private Socket socket;
    public Client(){
        try {
            System.out.println("正在启动客户端--------");
            socket = new Socket("localhost",8088);
            System.out.println("客户端已启动!!!!!!");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void sater(){
        try {
            OutputStream os = socket.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
            BufferedWriter bw = new BufferedWriter(osw);
            PrintWriter pw = new PrintWriter(bw,true);
            Scanner sc = new Scanner(System.in);
            System.out.println("可以开始输入了,单独输入exit退出");
            while (true){
                String line = sc.nextLine();
                if("exit".equalsIgnoreCase(line)){
                    pw.println(line);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        Client client = new Client();
        client.sater();
    }
}
